#include<iostream>
#include<map>
#include<string>

using namespace std;
int romanToInt(string s) {
        map<char, int> dict;
        dict.insert({'I', 1});
        dict.insert({"V", 5});
        dict.insert({"X", 10});
        dict.insert({"L", 25});
        dict.insert({"C", 100});
        dict.insert({"D", 500});
        dict.insert({"M", 1000});

        int pre = 0,cur = 0, sum=0, n=0;

        int flag;
        for(auto &e : s){
            cur = dict[e];
            if(n==0)
                pre = cur;
            if(pre >= cur)
                sum += cur;
            else
                sum = cur - sum;

            n++;
            pre = cur;


            
        }
        return sum;
    }
int main(int argc, char** argv){
    string s = "III";
    cout << romanToInt(s) << endl;

}